# coding=utf-8
'''
Created on Jun 17, 2009

@license: License: LGPL
@copyright: (c) 2009, dogsing.cn
@author: ant-man
'''

from mocCallable import MocNativeCall
from mocConstant import mocString
from mocCollection import mocDict

VERSION = "0.1"
AUTHOR = "Bin Zhao (antmanler at gmail.com)"

_moc_sys = {
 "version" : mocString.new_inst(repr(VERSION)) ,
 "author" : mocString.new_inst(repr(AUTHOR))
}
_moc_sys_obj = mocDict.new_inst(_moc_sys)


def moc_print(out, formated, *args):
    """
    TODO:
    """
    src = formated % tuple(args) if len(args) > 0 else formated
    print >> out, src


def init_intp(intp, sys_out, sys_obj=_moc_sys):
    natives = (
              MocNativeCall(lambda formated, *args:moc_print(sys_out, formated, *args), "print"),
              )
    intp.register_native_calls(natives)
    add_ctx = {"sys": _moc_sys_obj.id}
    intp.ctx.ctx.update(add_ctx)
